import { getSystemTab } from '~shared/utils/tab'
import { TAB_IDS } from '~shared/constants'
import { WINDOW_STYLE_CONSTANTS } from '~shared/constants/layout'

export function openViewImage(
  list: { file_path: string }[],
  index?: number,
  opt?: { width?: number; height?: number }
) {
  const screenWidth = window.screen.width
  const screenHeight = window.screen.height
  const box = {
    minWidth: 650,
    minHeight: 600,
    maxWidth: screenWidth * 0.9,
    maxHeight: screenHeight * 0.9
  }
  const { RIGHT_HEADER_HEIGHT, VIEW_BORDER_WIDTH } = WINDOW_STYLE_CONSTANTS,
    h = (opt?.height || 600) + RIGHT_HEADER_HEIGHT + VIEW_BORDER_WIDTH,
    w = (opt?.width || 800) + VIEW_BORDER_WIDTH * 2
  const width = Math.max(box.minWidth, Math.min(w, box.maxWidth))
  const height = Math.max(box.minHeight, Math.min(h, box.maxHeight))
  _pre_.browser.addTab(
    getSystemTab(TAB_IDS.IMAGE_PREVIEW, {
      isInSeparateWindow: true,
      separateConfig: { width, height },
      data: { list, index }
    }),
    'right'
  )
}

export function openNotice(data: { type: string; val: unknown }) {
  _pre_.browser.addTab(getSystemTab(TAB_IDS.NOTICE, { isInSeparateWindow: true, data }), 'right')
}
